﻿using System;
using System.Collections;
using System.Configuration;
using System.Web;

namespace InternetBankService
{
    using Castle.Facilities.WcfIntegration;
    using Castle.MicroKernel.Registration;
    using Castle.Windsor;

    using InternetBankService.Helpers;
    using InternetBankService.Model;
    using InternetBankService.Data;

    public class Global : HttpApplication
    {
        IWindsorContainer _container;

        protected void Application_Start(object sender, EventArgs e)
        {
            _container = new WindsorContainer();

            _container.AddFacility<WcfFacility>().Register(
                Component.For<IRepository>().ImplementedBy<Repository>().DependsOn(
                    new Hashtable
                        {
                            {
                                "dataContext",
                                new BankInfoDataContext(
                                ConfigurationManager.ConnectionStrings["BankInfoConnectionString"].ConnectionString)
                                }
                        }),
                Component.For<IHashClaculator>().ImplementedBy<MD5HashClaculator>(),
                Component.For<IMailSender>().ImplementedBy<MailHelper>(),
                Component.For<IPaymentsService>().ImplementedBy<PaymentsService>().Named(
                    "InternetBankService.PaymentsService"));
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            if (_container != null)
                _container.Dispose();
        }
    }
}